home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.001 / crossfir~ / eutl / debuglib / debuglib.c next >
C/C++ Source or Header  |  1994-09-19  |  2KB  |  102 lines

  1. #include "debuglib.h"
  2. #include <errlib.h>
  3. #include <sys/types.h>
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. #include <chain-hash.h>
  9. #include <libc.h>
  10.  
  11. char *debuglib_packagever = "DebugLib V1.0";
  12. char *debuglib_Ecantcreatetable = "Unable to create debugging table";
  13. char *debuglib_Egeterror = "Error Getting stored value from table";
  14.  
  15. static ErrorFunction Erf = LongJmpErrorFunction;
  16.  
  17. static HashTable debugtable;
  18. int __debuglib_debugging_on;
  19.  
  20. void SetDebuggingValue(char *arg,int val)
  21. {
  22.   if (!debugtable) {
  23.     debugtable = CreateHashTable(-500,NULL);
  24.     if (debugtable == NULL) {
  25.       Erf(debuglib_packagever,debuglib_Ecantcreatetable,
  26.       "Unable to create the debugging table\n");
  27.     }
  28.     __debuglib_debugging_on = 1;
  29.   }
  30.   HashOverwrite(debugtable,arg,strlen(arg),&val,sizeof(int));
  31. }
  32.  
  33. void GetDebuggingArguments(int *argc,char **argv)
  34. {
  35.   int l;
  36.   for(l=1;l<*argc;l++) {
  37.     if (*(argv[l]) == '-') {
  38.       char *e; /* equal pos */
  39.       char *a; /* arg */
  40.       int v; /* value */
  41.       int j; /* loop for moving argv down */
  42.       if (*(argv[l]+1) == '-')
  43.     break; /* Respect -- convention as end of arguments */
  44.       if (*(argv[l]+1) != 'D')
  45.     continue; /* not our argument */
  46.       if ((e = index(argv[l],'=')) != NULL) {
  47.     *e = '\0';
  48.       }
  49.       /* Grab values */
  50.       a = strdup(argv[l]);
  51.       if (e) {
  52.     v = atoi(e+1);
  53.       } else {
  54.     v = 1;
  55.       }
  56.       /* Shift down argv stuff */
  57.       (*argc)--;
  58.       l--; /* since argv shifted down, backup the loop */
  59.       for(j=l;j<*argc;j++)
  60.     argv[j] = argv[j+1];
  61.       /* Store Debugging Information */
  62.       SetDebuggingValue(a+2,v);
  63.       free(a);
  64.     }
  65.   }
  66. }
  67.  
  68. int GetDebuggingValue(char *debugname)
  69. {
  70.   int ret,found;
  71.   char *c; /* copy */
  72.   char *t; /* tmp for backing up the debugging name being checked */
  73.  
  74.   found = 0;
  75.   c = strdup(debugname);
  76.   if (c==NULL)
  77.     Erf(debuglib_packagever,debuglib_Egeterror,
  78.     "Error duplicating string '%s'\n",debugname);
  79.   while(1) {
  80.     WITH_HANDLING {
  81.       ret = *(int *)HashLookup(debugtable,c,strlen(c));
  82.       found = 1;
  83.     } HANDLE {
  84.       BEGIN_MATCH;
  85.       XMATCH(chainhash,badlookup) {
  86.       } END_MATCH;
  87.     } END_HANDLING;
  88.     if (found)
  89.       break;
  90.     /* Backup the debugging name */
  91.     t = rindex(c,':');
  92.     if (t==NULL) {
  93.       free(c);
  94.       return 0;/* Not found and no parent found */
  95.     }
  96.     *t = '\0';
  97.   }
  98.   free(c);
  99.   return ret;
  100. }
  101.  
  102.